package mybatis.hr.main;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import mybatis.hr.dao.DepartmentDAO;
import mybatis.hr.domain.Department;
import mybatis.hr.domain.Employee;

public class DepartmentTest {
	public static void main(String[] args) {
		DepartmentDAO dao = DepartmentDAO.getInstance();
		Department dept1 = new Department(300, "기획부", "서울");
		int cnt = 0;
	//	cnt = dao.insertDepartment(dept1);
	//	System.out.println("insert 개수 : " + cnt);

		
//		dept1.setLocation("부산");
//		cnt = dao.updateDepartment(dept1);
//		System.out.println("update개수 : " + cnt);
//		cnt = dao.deleteDeparmentByNo(1);
//		System.out.println("삭제 개수 : " + cnt);
//		cnt = dao.deleteDepartmentByLocation("서울");
//		System.out.println("삭제 개수 : " + cnt);
		
		Department dept = dao.selectDepartmentByNo(2);
		System.out.println(dept);
		
//		System.out.println("---------전체목록 조회-------------");
//		List<Department> list = dao.selectDepartmentList();
//		for(Department d : list) {
//			System.out.println(d);
//		}
//		
//		System.out.println("------------전체목록 조회 ---- MAP -----");
//		Map<Integer, Department> map = dao.selectDepartmentList_Map();
//		//map은 for문 못돌린다 -> Entry를 가져오던지 해야함 (entry = key+value -> set = entry들)
//		Set<Entry<Integer,Department>> set = map.entrySet();
//		for(Entry<Integer,Department> e: set) {
//			System.out.println(e.getKey() + " --- " + e.getValue());
//		}
		
		System.out.println("-------location List 조회 ------");
		List<Department> list = dao.selectDepartmentByLocation_List("서울");
		for(Department d : list) {
			System.out.println(d);
		}
		
		System.out.println("-----------location Map 조회 -----");
		Map<Integer, Department> map = dao.selectDepartmentByLocation_Map("부산");
		//map은 for문 못돌린다 -> Entry를 가져오던지 해야함 (entry = key+value -> set = entry들)
		Set<Entry<Integer,Department>> set = map.entrySet();
		for(Entry<Integer,Department> e: set) {
			System.out.println(e.getKey() + " --- " + e.getValue());
		}
		
		System.out.println("---------이름으로 list조회------");
		List<Department> list2 = dao.selectDepartmentByName("인사부");
		for(Department d : list2) {
			System.out.println(d);
		}
		
		System.out.println("-------------Employee와 Join조회-------");
		Department dd= dao.selectDepartmentJoinEmployee(1);
		System.out.println(dd);
		ArrayList<Employee> emps = dd.getEmployees();
		for(Employee e : emps)	{
			System.out.println(e);
		}
	}
}

